#ifndef RANDOMMUSICCLOCK_H
#define RANDOMMUSICCLOCK_H

#include <QtWidgets/QDialog>
#include "ui_randommusicclock.h"
#include <QNetworkReply>
#include <QMediaPlayer>

class RandomMusicClock : public QDialog
{
	Q_OBJECT

public:
	RandomMusicClock(QWidget *parent = 0);
	~RandomMusicClock();

	void initTrayIcon();
	void createActions();
	void createMenu();

	void initPlayer();
	void initCfg();
	void saveCfg();
	void initAudio();

	void setAudioOutpurDev();
	void keyPressEvent(QKeyEvent* e);
	void closeEvent(QCloseEvent *e);
	bool parseMusic(const QByteArray& ba);

	bool getMusic();
	bool startDownloadFile();
	void insertLog(QString text);
	void playUrl(const QUrl &url);
	bool checkExecute();
	void setBackgroundImage(QString path);

#ifdef Q_OS_WIN
	void setAutoRun();
#endif

public slots:
	void showTime();
	void on_pushButton_browser_clicked();
	void on_pushButton_start_clicked();
	void sltFinishRequest(QNetworkReply *reply);
	void sltHttpFinished();
	void sltHttpReadyRead();
	void sltHttpError(QNetworkReply::NetworkError eError);
	void sltScheduleTimerOut();

	void togglePlayback();
	void updateState(QMediaPlayer::State state);
	void updatePosition(qint64 position);
	void updateDuration(qint64 duration);
	void setPosition(int position);
	void updateInfo();
	void handleError();
	void timeChanged(const QTime & time);
	void onlyWorkdayStateChanged(int state);
	void releaseVolumeBotton();
	void sltShowMainAction();
	void sltExitAppAction();
	void sltActivatedTrayIcon(QSystemTrayIcon::ActivationReason reason);
	void audioComboxChanged(const QString& text);
public:

private slots:
    void on_comboBox_type_currentIndexChanged(const QString &arg1);

private:
	Ui::RandomMusicClockClass ui;

	QNetworkReply *m_getMusicReply;
	QNetworkReply *m_downloadReply;

	QUrl m_url;
	QNetworkAccessManager *m_pManager;
	QTime m_tStartTime;
	bool m_bOnlyWorkDay;
	QString m_strSaveDir;

	QDateTime m_dtLastRunTime;
	bool m_bFirstRun;
	QTimer* m_ScheduleTimer;
	int m_nVolume;
	QString m_strAudio;

	QString m_strName;
	QString m_strUrl;
	QString m_strFilePath;
	QString m_strFileName;

	QFile* m_pFile;

	QMediaPlayer m_mediaPlayer;

	QMenu* m_SysTrayMenu;
	QMenu* m_MainMenu;

	QAction* m_ShowMainAction;
	QAction* m_ExitAppAction;
	QSystemTrayIcon* m_SystemTrayIcon;
	bool m_bClose;
    QString m_strType;
};

#endif // RANDOMMUSICCLOCK_H
